var express = require("express");
var bodyParser = require("body-parser");
// 创建项目实例
const app = express();
// 加载路由控制
var routes = require("./routes/index");

// 定义数据解析器
// parse application/x-www-form-urlencoded           body-parser  插件 数据问题
app.use(bodyParser.urlencoded({ extended: false }));
// parse application/json
app.use(bodyParser.json());

// 跨域等
app.all("*", function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Methods", "PUT, GET, POST, DELETE, OPTIONS");
  res.header("Access-Control-Allow-Headers", "X-Requested-With");
  res.header("Access-Control-Allow-Headers", ["mytoken", "Content-Type"]);
  next();
});

// 匹配路径和路由
app.use("/", routes);

// console.log("111", routes);

// app.listen("80", function() {
//   console.log("80");
// });
app.listen(3000);
module.exports = app;
